script_enemy_main{

let sun=0;
let glow=0;
let scale=0;

let angle1=0;
let angle2=0;
let baseangle=rand(0,360);
let phase=rand_int(0,1);
let frame2=0;

let character="Youko";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=6;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshotb5=("\script\SoundEffects\shotb5.wav");
let SEshotm3=("\script\SoundEffects\shotm3.wav");
let SElasers1=("\script\SoundEffects\lasers1.wav");

let EFsun=("\script\Images\BackgroundLayers\Youko1b.png");
let EFglow=("\script\Images\BackgroundLayers\Youko1c.png");
let BG1=("\script\Images\BackgroundLayers\Witches1.png");
let GRboss=("\script\Images\CharacterSprites\Youko.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsYouko1.txt");

	LoadSE("\script\SoundEffects\shotb5.wav");
	LoadSE("\script\SoundEffects\shotm3.wav");
	LoadSE("\script\SoundEffects\lasers1.wav");

	LoadGraphic("\script\Images\BackgroundLayers\Youko1b.png");
	LoadGraphic("\script\Images\BackgroundLayers\Youko1c.png");
	LoadGraphic("\script\Images\BackgroundLayers\Witches1.png");
	LoadGraphic("\script\Images\CharacterSprites\Youko.png");
	
	SetScore(100000);
	SetLife(300);
	SetTimer(30);
	SetInvincibility(120);
	SetDamageRate(10,10); 
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+70,50);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(32,32,32,32);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=7; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("Corona [Blazing Photosphere] ("~difficulty~")",spellcardnumber); 
HealthBar();
Portrait(cutin,1);


if(time==60){
let xsize=256;
let ysize=256;
	sun=(Obj_Create(OBJ_EFFECT));
	Obj_SetCollisionToPlayer(sun,true); Obj_SetPosition(sun,cx,cy); ObjEffect_SetScale(sun,scale,scale);
	ObjEffect_SetLayer(sun,2); ObjEffect_SetTexture(sun,EFsun); ObjEffect_SetRenderState(sun,ADD);
	ObjEffect_SetPrimitiveType(sun,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(sun,4);
	ObjEffect_SetVertexXY(sun,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(sun,0,0,0);
	ObjEffect_SetVertexXY(sun,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(sun,1,xsize,0);
	ObjEffect_SetVertexXY(sun,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(sun,2,0,ysize);
	ObjEffect_SetVertexXY(sun,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(sun,3,xsize,ysize);
	ObjEffect_SetVertexColor(sun,0,255,255,255,255); ObjEffect_SetVertexColor(sun,1,255,255,255,255);
	ObjEffect_SetVertexColor(sun,2,255,255,255,255); ObjEffect_SetVertexColor(sun,3,255,255,255,255);

	glow=(Obj_Create(OBJ_EFFECT));
	Obj_SetCollisionToPlayer(glow,true); Obj_SetPosition(glow,cx,cy); ObjEffect_SetScale(glow,scale,scale);
	ObjEffect_SetLayer(glow,2); ObjEffect_SetTexture(glow,EFglow); ObjEffect_SetRenderState(glow,ADD);
	ObjEffect_SetPrimitiveType(glow,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(glow,4);
	ObjEffect_SetVertexXY(glow,0,-(xsize/2),-(ysize/2)); ObjEffect_SetVertexUV(glow,0,0,0);
	ObjEffect_SetVertexXY(glow,1,xsize/2,-(ysize/2)); ObjEffect_SetVertexUV(glow,1,xsize,0);
	ObjEffect_SetVertexXY(glow,2,-(xsize/2),ysize/2); ObjEffect_SetVertexUV(glow,2,0,ysize);
	ObjEffect_SetVertexXY(glow,3,xsize/2,ysize/2); ObjEffect_SetVertexUV(glow,3,xsize,ysize);
	ObjEffect_SetVertexColor(glow,0,150,255,255,255); ObjEffect_SetVertexColor(glow,1,150,255,255,255);
	ObjEffect_SetVertexColor(glow,2,150,255,255,255); ObjEffect_SetVertexColor(glow,3,150,255,255,255);
}

let sunsize=1.8;

SetCollisionB(cx,cy,90*scale);
if(scale<sunsize && time>=60){ scale+=0.01; }
ObjEffect_SetScale(sun,scale,scale);
ObjEffect_SetScale(glow,scale*1.1,scale*1.1);
ObjEffect_SetAngle(sun,0,0,time/7);
if(time%5==0 && time>=60){ ObjEffect_SetAngle(glow,0,0,rand(0,360)); }


if(time%60==0 && scale>=sunsize){
let angle=rand(0,360);
	loop(10){
		loop(10){
		CreateShot01(GetX,GetY,rand(1.3,1.4),angle,2,20);
		angle+=360/10;
		}
	angle+=rand(2,3.5);
	}
usespell=20;
PlaySE(SEshotm3);
}


frame2++;
if(frame2==90 || frame2==105 || frame2==120 || frame2==210 || frame2==300 && time>120){
let angle=GetAngleToPlayer-30;
	loop(5){
	CreateShot02(GetX,GetY,4,angle,-0.1,1,25,20);
	angle+=15;
	}
usespell=-20;
PlaySE(SEshotb5);
}
if(frame2==300){ frame2=0; }


if(time%2==0 && scale>=sunsize && frame>=60){
let shot1=0;
	if(phase%2==0){
	CreateLaserA(shot1,cx+(70*scale)*cos(baseangle+angle1),cy+(70*scale)*sin(baseangle+angle1),300,10,23,40);
	SetLaserDataA(shot1,0,baseangle+angle1,0.3,0,0,0);
	SetShotKillTime(shot1,120);
	FireShot(shot1);
	PlaySE(SElasers1);
	}
	if(phase%2!=0){
	CreateLaserA(shot1,cx+(70*scale)*cos(baseangle-angle2),cy+(70*scale)*sin(baseangle-angle2),300,10,23,40);
	SetLaserDataA(shot1,0,baseangle-angle2,-0.3,0,0,0);
	SetShotKillTime(shot1,120);
	FireShot(shot1);
	PlaySE(SElasers1);
	}
angle1+=10;
angle2+=10;
}

if(angle1>360 || angle2>360){ baseangle=rand(0,360); angle1=0; angle2=0; phase+=1; frame=-30; }



time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";
}

@BackGround{
	if(bgfade<255){ bgfade+=5; }

	SetGraphicRect(0,0,512,512);
	SetGraphicScale(1.2,1.2);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,60*cos(time/4));
	DrawGraphic(cx,cy);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	if(GetLife>0){ DrawGraphic(GetX,GetY); }
}

@Finalize{
	SetCommonData("Conversation",1);
	NewPointData(spellcardnumber,GetCommonData("Difficulty"));
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}